﻿
using CSharpLibs.Annotations;

#pragma warning disable 0169

namespace System
{
	[Builtin]
	public struct Char : IUSignIntegralValue, IComparable, IComparable<Char>, IEquatable<Char>
	{
		[DummyPrimitiveField]
		private char ff;

		public int CompareTo(object o)
		{
			if(!(o is Char))
				Environment.Exit(1);

			return PrimitiveHelper.DoCompareOpIntegral(this, (Char)o);
		}

		public int CompareTo(Char c)
		{ return PrimitiveHelper.DoCompareOpIntegral(this, c); }

		public override bool Equals(object o)
		{ return (o is Char) && (this == ((Char)o)); }

		public bool Equals(Char c)
		{ return this == c; }

		public override int GetHashCode()
		{ return (((char)this) | (((char)this) << 0x10)); }

		public static char Parse(string sv)
		{ return (char)PrimitiveHelper.ParseUSignIntegral(sv); }

		public override string ToString()
		{ return PrimitiveHelper.USignIntegralToString(this); }

		public static bool IsDigit(char c)
		{ return ((c >= '0') && (c <= '9')); }

		public static bool IsLetter(char c)
		{
			c = (char)(c | ' ');
			return ((c >= 'a') && (c <= 'z'));
		}
		public static bool IsLower(char c)
		{ return ((c >= 'a') && (c <= 'z')); }

		public static bool IsNumber(char c)
		{ return ((c >= '0') && (c <= '9')); }

		public static bool IsUpper(char c)
		{ return ((c >= 'A') && (c <= 'Z')); }

		[BuiltinMethod, BuiltinSemantics("char_is_whitepace")]
		public static bool IsWhiteSpace(char c)
		{ return false; }

		public static char ToLower(char c)
		{
			if(IsLower(c))
				return (char) (c - 32);
			else
				return c;
		}

		public static char ToUpper(char c)
		{
			if(IsUpper(c))
				return (char) (c + 32);
			else
				return c;
		}

		public static bool IsLetterOrDigit(char c)
		{ return IsLetter(c) | IsDigit(c); }
	}
}

#pragma warning restore 0169

